// 基于 swagger.yaml 生成的 TypeScript 类型定义

// 基础响应类型
export interface ApiResponse<T = any> {
  data?: T;
  message?: string;
  error?: string;
}

export interface ListResponse<T> {
  count: number;
  items: T[];
  // 根据实际 API 响应调整字段名
  connections?: T[];
  domains?: T[];
  pools?: T[];
  volumes?: T[];
  networks?: T[];
}

// 连接管理相关类型
export interface ConnectionDetail {
  name: string;
  uri: string;
  connected: boolean;
  hostname?: string;
  version?: number;
}

export interface CreateConnectionRequest {
  name: string;
  uri: string;
  set_as_default?: boolean;
}

// 虚拟机管理相关类型
export interface DomainSummary {
  name: string;
  uuid: string;
  state: string;
  vcpus?: number;
  memory?: number;
}

export interface DomainDetail {
  name: string;
  uuid: string;
  state: string;
  vcpus: number;
  memory: number;
  max_memory: number;
  cpu_time: number;
  xml_config: string;
}

export interface CreateDomainRequest {
  name: string;
  uuid?: string;
  memory: number; // MiB
  vcpus: number;
  disk_path: string;
  disk_size: number; // GiB
  disk_bus?: 'virtio' | 'sata' | 'scsi';
  architecture?: 'x86_64' | 'aarch64';
  boot_mode?: 'bios' | 'uefi';
  secure_boot?: boolean;
  cdrom_boot?: boolean;
  cdrom_path?: string;
  cdrom_bus?: 'ide' | 'sata' | 'scsi';
  network_mode?: 'network' | 'bridge' | 'user';
  network_name?: string;
  os_variant?: string;
  auto_start?: boolean;
}

// 存储管理相关类型
export interface StoragePoolSummary {
  name: string;
  uuid: string;
  type: string;
  active: boolean;
}

export interface StoragePoolDetail {
  name: string;
  uuid: string;
  type: string;
  active: boolean;
  capacity: number;
  allocation: number;
  available: number;
  xml_config: string;
}

export interface StorageVolumeSummary {
  name: string;
  type: string;
  path: string;
}

export interface StorageVolumeDetail {
  name: string;
  type: string;
  path: string;
  capacity: number;
  allocation: number;
  xml_config: string;
}

export interface CreateVolumeRequest {
  name: string;
  capacity: number; // bytes
  format?: 'qcow2' | 'raw' | 'vmdk' | 'vdi';
}

// 网络管理相关类型
export interface NetworkSummary {
  name: string;
  uuid: string;
  active: boolean;
  bridge?: string;
}

export interface NetworkDetail {
  name: string;
  uuid: string;
  active: boolean;
  bridge?: string;
  xml_config: string;
}

// 系统信息相关类型
export interface SystemInfo {
  hostname: string;
  uri: string;
  libvirt_version: number;
  hypervisor_version: number;
}

// 控制台相关类型
export interface ConsoleInfo {
  type: 'vnc' | 'spice' | 'serial';
  host?: string;
  port?: number;
  password?: string;
  tls_port?: number;
  websocket_url?: string;
}

// 域状态枚举
export const DomainState = {
  RUNNING: 'running',
  SHUTOFF: 'shut off',
  PAUSED: 'paused',
  SUSPENDED: 'suspended',
  CRASHED: 'crashed',
  UNKNOWN: 'unknown',
} as const;

export type DomainStateType = typeof DomainState[keyof typeof DomainState];

// 连接状态枚举
export const ConnectionState = {
  CONNECTED: 'connected',
  DISCONNECTED: 'disconnected',
  ERROR: 'error',
  UNKNOWN: 'unknown',
} as const;

export type ConnectionStateType = typeof ConnectionState[keyof typeof ConnectionState];

// 存储池状态枚举
export const StoragePoolState = {
  ACTIVE: 'active',
  INACTIVE: 'inactive',
  ERROR: 'error',
} as const;

export type StoragePoolStateType = typeof StoragePoolState[keyof typeof StoragePoolState];

// 网络状态枚举
export const NetworkState = {
  ACTIVE: 'active',
  INACTIVE: 'inactive',
  ERROR: 'error',
} as const;

export type NetworkStateType = typeof NetworkState[keyof typeof NetworkState];

// 操作类型
export type DomainOperation = 
  | 'start'
  | 'shutdown'
  | 'force-stop'
  | 'reboot'
  | 'suspend'
  | 'resume';

export type NetworkOperation = 'start' | 'stop';
export type StoragePoolOperation = 'start' | 'stop';

// 错误类型
export interface ApiError {
  message: string;
  code?: string;
  details?: any;
}

// 分页参数
export interface PaginationParams {
  page?: number;
  limit?: number;
  offset?: number;
}

// 过滤参数
export interface FilterParams {
  search?: string;
  state?: string;
  type?: string;
  active?: boolean;
}

// 排序参数
export interface SortParams {
  sortBy?: string;
  sortOrder?: 'asc' | 'desc';
}

// 综合查询参数
export interface QueryParams extends PaginationParams, FilterParams, SortParams {
  connection?: string;
}